#include "deviceCode.h"
#include "hardware.h"
#include "stringUtils.h"

DeviceCode::DeviceCode() 
{
	Char buf[SERIALNUM_LENTH] = { 0 };
	Hardware hw;
	hw.Init();
	hw.GetBaseBoardSerialNum(buf, SERIALNUM_LENTH);
	String sn = buf;
	StringUtils::trim(sn);
	case_insensitive_string s1(sn.c_str());
	if (s1.empty() || s1 == L"Default string" || s1 == L"None"
		|| s1 == L"Not Applicable" || s1 == L"Base Board Serial Number") {
		memset(buf, 0, SERIALNUM_LENTH * sizeof(Char));
		hw.GetComputerUuid(buf, SERIALNUM_LENTH);
		sn = buf;
		StringUtils::trim(sn);
		memset(buf, 0, SERIALNUM_LENTH*sizeof(Char));
		swprintf_s(buf, SERIALNUM_LENTH, L"PC_UUID_%s", sn.c_str());
		deviceCode = buf;
	}
	else {
		memset(buf, 0, SERIALNUM_LENTH * sizeof(Char));
		swprintf_s(buf, SERIALNUM_LENTH, L"PC_%s", sn.c_str());
		deviceCode = buf;
	}
	
	hw.Deinit();
}

DeviceCode::~DeviceCode()
{
	
}

DeviceCode& DeviceCode::inst()
{
	static DeviceCode instance;
	return instance;
}

const wchar_t* DeviceCode::getDeviceCode() const
{
	return deviceCode.c_str();
}
